<?php
namespace Api;
use Kuyuan\WqCore\api\Api;
use Kuyuan\WqCore\cache\Cache;
use Kuyuan\WqCore\util\Util;

/**
 * 后台扫码获取基础信息组件member-input
 * Class ImageInput
 * @package Api
 */
class MemberInput extends Api
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取扫码二维码url地址
     */
    public function getQrcodeUrl()
    {
        Util::appointGet();
        $Qrcode = $this->newController("Qrcode");
        $_url = murl('entry//scan', $Qrcode->createParams($this->_gpc["data"]), true, true);
        Util::returns(array("code"=>0,"data"=>$_url));
    }

    /**
     *监听扫码，并且返回用户信息
     */
    public function listenScan()
    {
        Util::appointGet();
        $_manage_id = Cache::name(KUYUAN_NAME."_manage_uid");
        $_result = array("code"=>100);
        if($_manage_id) {
            $Member = $this->newController("Member");
            Cache::name(KUYUAN_NAME."_manage_uid",null);
            $_data = array_merge(array("uid"=>$_manage_id),$Member->findNameHeader($_manage_id));
            $_result = array("code"=>0,"data"=>$_data);
        }
        Util::returns($_result);
    }

    /**
     * 检测二维码是否过期
     */
    public function testPast()
    {
        Util::appointGet();
        $Qrcode = $this->newController("Qrcode");
        if($Qrcode->testQrcode($this->_gpc["data"])) {
            $_result = array("code"=>0);
        } else {
            $_result = array("code"=>100);
        }
        Util::returns($_result);
    }

    /**
     * 获取头像和用户昵称
     */
    public function getAvatarNickname()
    {
        Util::appointGet();
        $Member = $this->newController("Member");
        Util::returns(array(
            "code" => 0,
            "data" => $Member->findNameHeader($this->_gpc["uid"])
        ));
    }
}